#include <cstdio>
#include <vector>


const int N = 1e4 + 9;
std::vector<int> blocks[N];


/**
 * 
 * 时间复杂度：O(mn)
 * 空间复杂度：O(n)
 * 
 * 移动积木
 *
 * @return 
 */
int main() {
	int n, m;
	scanf("%d %d", &n, &m);

	for (int i=1; i<=n; i++) {
		blocks[i].push_back(i);
	}

	while (m--) {
		int a, b;
		scanf("%d%d", &a, &b);
		if (a==b) {
			continue;
		}

		blocks[a].insert(blocks[a].end(), blocks[b].begin(), blocks[b].end());
		blocks[b].clear();

	}

	for (int i=1; i<=n; i++) {
		for (int j=0; j<blocks[i].size(); j++) {
			printf("%d ", blocks[i][j]);
		}
		printf("\n");
	}


	return 0;
}